﻿
using System;
using System.Collections.ObjectModel;
using FXSStation.Modules.SharedInfrastructureModule.BusinessClasses.Accounts;
using FXSStation.Modules.SharedInfrastructureModule.BusinessClasses.Orders;
namespace FXSStation.Modules.SharedInfrastructureModule.BusinessClasses.Reports
{
    [Serializable]
    public class Report : ReportBase
    {
        public Report(ReportType type)
        {
            this.Type = type;
        }
        //public static ComparisonReport CreateComparisonReport(Account account1, Account account2)
        //{
        //    ComparisonReport report = new ComparisonReport(account1, account2);
        //    report.PrimaryReports = CreateFullReportFor(report.Account);
        //    report.SecondaryReports = CreateFullReportFor(report.SecondaryAccount);
        //    return report;
        //}
        public static ObservableCollection<Report> CreateFullReportFor(Account account)
        {
            if (account == null)
            {
                return new ObservableCollection<Report>();
            }
            ObservableCollection<Report> reports = new ObservableCollection<Report>();
            foreach (Session session in account.Sessions)
                reports.Insert(0,CreateSessionReport(session));

            return reports;
        }
        public static Report CreateSessionReport(Session session)
        {
            Report report = new Report(ReportType.Session);
            //report.Account = this.CurrentAccount;
            report.Currency = session.CurrencySymbol;
            report.StartDate = session.TimeStampStart;
            report.EndDate = session.TimeStampEnd;
            report.Orders = session.ClosedOrders;
            report.Profit = CalculateProfit(report.Orders);
            //this.Reports.Add(report);
            return report;
        }
        private static decimal CalculateProfit(ObservableCollection<OrderBase> orders)
        {
            decimal profit = 0;
            foreach (OrderBase order in orders)
                profit += order.Profit;

            return profit;
        }
        
    }
}
